package com.example.demo.elasticsearch;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName BlogController
 * @Description:
 * @Author liyunjiang
 * @Date 2020/5/17 21:15
 */
@RestController
@RequestMapping("/blog")
public class BlogController {
    @Autowired
    BlogService blogService;


    @PostMapping("/add")
    public String add(@RequestBody BlogEntity entity){
        entity.setTime(new Date());
        blogService.add(entity);
        return "ok";
    }

    @GetMapping("/get/{id}")
    public BlogEntity getById(@PathVariable String id){
        return blogService.getById(id);
    }
    @GetMapping("/list")
    public List<BlogEntity> list(){
        return blogService.list();
    }
    @PostMapping("/update")
    public String update(@RequestBody BlogEntity entity){
        blogService.update(entity);
        return "ok";
    }
    @GetMapping("/findByTitle/{keywords}")
    public List<BlogEntity> findByTitle(@PathVariable String keywords){
        return blogService.findByTitle(keywords);
    }
}
